package ace.tool.generate.code.impl.resolver.scheme.resolver.core;

import ace.tool.generate.code.impl.resolver.scheme.model.bo.core.resources.LiquibaseInitTableFileInfo;
import ace.tool.generate.code.impl.resolver.scheme.model.dto.ProjectInfo;
import ace.tool.generate.code.impl.service.model.input.GenerateInput;
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.apache.commons.text.StringSubstitutor;

/**
 * @author caspar
 * @date 2023/11/17 10:34
 */
@RequiredArgsConstructor
public class LiquibaseInitTableFileInfoResolver {
  private final GenerateInput input;
  private final ProjectInfo coreProjectInfo;

  public LiquibaseInitTableFileInfo resolve() {
    return LiquibaseInitTableFileInfo.builder()
        .fileName(input.getLiquibaseInitTableFileName())
        .fileFullName(this.getFileFullName())
        .build();
  }

  private String getFileFullName() {
    Map<String, String> data = new HashMap<>();
    data.put("rootDir", coreProjectInfo.getResourcesRootDir());
    data.put("fileRootDir", input.getLiquibaseInitTableFileRootDir());
    data.put("fileName", input.getLiquibaseInitTableFileName());
    return StringSubstitutor.replace("${rootDir}/${fileRootDir}/${fileName}", data);
  }
}
